﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Web.Models;
using FwProject.Controllers;
using FwProject.EventAdvertising;
using FwProject.EventAdvertising.Dto;
using Microsoft.AspNetCore.Mvc;

namespace FwProject.Web.Shop.Controllers
{
    public class NoticeController : FwProjectControllerBase
    {
        private readonly INoticeAppService _noticeAppService;

        public NoticeController(INoticeAppService noticeAppService)
        {
            _noticeAppService = noticeAppService;
        }

        /// <summary>
        /// 公告列表
        /// </summary>
        /// <returns></returns>
        [DisableAuditing]
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 获取公告列表数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [DisableAuditing]
        [WrapResult(false, false)]
        public async Task<IActionResult> GetNoticeData(int page, int limit)
        {
            var model = await _noticeAppService.GetNoticeDataAsync(page, limit);
            return Json(model);
        }
        /// <summary>
        /// 修改公告启用状态
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> SwitchActive(Guid id, bool active)
        {
            await _noticeAppService.UpdateActive(id,active);
            return Json(1);
        }
        /// <summary>
        /// 添加公告
        /// </summary>
        /// <returns></returns>
        public IActionResult Create()
        {
            return View();
        }

        public async Task<IActionResult> CreateNotice(NoticeInput input)
        {
            var id =  await _noticeAppService.Create(input);
            return Json(id);
        }
        /// <summary>
        /// 编辑公告
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> Edit(Guid id)
        {
            ViewBag.Id = id;
            var model = await _noticeAppService.GetByIdAsync(id);
            return View(model);
        }

        public async Task<IActionResult> EditNotice(Guid id,NoticeInput input)
        {
            await _noticeAppService.Update(id,input);
            return Json(id);
        }
        /// <summary>
        /// 删除公告
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> DeleteNotice(Guid id)
        {
            await _noticeAppService.Delete(id);
            return Json(1);
        }
    }
}